<?php 

class Event_SpamPostSave extends Crud_Event_Handler 
{
	protected $_type = 'postSave';
	
	/**
	 * Run handler with options array.
	 * 
	 * @param OrdersRow $row
	 * @return void
	 */
	public function run($row)
	{
		
		
		$filters_all = $this->_getParam('filters_all');
		$oldFiltersRows = SpamFilterPeer::getInstance()->findByIdSpam($row->getId());
		foreach($oldFiltersRows as $oFR)
			$oFR->delete();
	
		if(strlen($filters_all)>0){
			$filters = preg_split("/::/",$filters_all);	
			foreach($filters as $filter)
				if(strlen($filter)>0){							
					preg_match("/([0-9]+)\|\|([0-9]+)\|\|(.+)\|\|/",$filter,$matches);				
					$filter_field = $matches[1];
					$filter_ratio = $matches[2];
					$filter_value = $matches[3];			
					$filterrow = SpamFilterPeer::getInstance()->createRow();
					$filterrow->setIdSpam($row->getId());
					$filterrow->setIdField($filter_field);
					$filterrow->setIdRatio($filter_ratio);
					$filterrow->setValue($filter_value);
					$filterrow->save();				
			}
		}
	}

}
